<template>
	<view id="box">
		<view class="goods--box">
			<view class="goods--item" v-for="(item, index) in massageList" :key="index" @click="toDetail(item)">
				<view class="item--cover" :style="{backgroundImage: 'url(' + item.images[0] + ')'}"></view>
				<view class="item--content">
					<view class="title">{{item.title}}</view>
					<view class="slod-num">已售{{item.buy_num}}
						<view class="lines"></view>好评{{(item.high_opinion/item.opinion || 0)*100}}%
					</view>
					<view class="price">{{item.price}}
						<view>元/次</view>
					</view>
				</view>
			</view>
		</view>
	<shaixuanPopup ref="shaixuanPopup" @massageResult="massageResult"></shaixuanPopup>
	</view>
</template>
<script>
	export default {
		name: "massageList",
		props: {
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
			category_id: {
				type: Number,
				default: 0
			},
			sort: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				massageList: [],
				massageResultData: {}
			}
		},
		watch: {
			category_id(olavalue, newvalue) {
				this.massageList = []
				this.page = 1
				this.getMassageList()
			},
			sort(olavalue, newvalue) {
				this.massageList = []
				this.page = 1
				this.getMassageList()
			}
		},
		mounted() {
			// this.getMassageList()
		},
		methods: {
			toDetail(item) {
				// this.$emit('onGoods', item)
				uni.navigateTo({
					url: '/otherpages/massage/massageDetail?id=' + item.id
				})
			},
			massageResult(data) {
				this.massageResultData = data
				this.massageList = []
				this.getMassageList()
			},
			screen() {
				this.$refs.shaixuanPopup.open()
			},
			getMassageList() {
				let that = this
				this.request.httpTokenRequest({
					url: "service/getServiceList",
					method: "get"
				}, {
					distance: this.massageResultData.slidernum,
					gender: this.massageResultData.slidernum,
					category_id: this.category_id,
					key: this.massageResultData.elsename,
					age: this.massageResultData.age,
					sort: this.sort,
					pageSize:10
				}).then(res => {
					if (res.code == 0) {
						res.data.data.map(item => {
							that.massageList.push(item)
						})
						this.$nextTick(()=>{
							const query = uni.createSelectorQuery().in(this);
							query.select('#box').boundingClientRect(data => {
								this.$emit('setData',{
									height:data.height,
									key:'height2'
								})
							}).exec();
						})
						
						that.page++
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			}
		}
	}
</script>
<style lang="scss" scoped>
	$padding: 30rpx;
	$margin: 10rpx;
	$radius: 20rpx;

	.ellipsis-1 {
		max-width: 100%;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.ellipsis-2 {
		max-width: 100%;
		display: -webkit-box;
		overflow: hidden;
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.goods--box {
		display: flex;
		flex-wrap: wrap;
		padding: $padding/3;

		.goods--item {
			background: white;
			width: calc(50% - #{$margin*2});
			background: white;
			border-radius: $radius;
			overflow: hidden;
			margin: $margin;

			.item--cover {
				width: 100%;
				padding-top: 100%;
				background-position: center;
				background-size: cover;
			}

			.item--content {
				padding: 20rpx;

				&>.title {
					font-size: 28rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #363737;
					line-height: 40rpx;
					margin-bottom: 10rpx;
				}

				&>.slod-num {
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #DE8C3E;
					line-height: 28rpx;
					margin-bottom: 10rpx;
					display: flex;
					align-items: center;

					.lines {
						width: 1rpx;
						height: 20rpx;
						border: 1rpx solid #DBDBDB;
						margin: 0 10rpx;
					}
				}

				&>.price {
					display: flex;
					align-items: center;
					line-height: 40rpx;
					font-weight: bold;
					color: #d4282d;
					font-size: 28rpx;
					line-height: 42rpx;

					view {
						font-size: 18rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #EC2700;
						line-height: 25rpx
					}
				}
			}
		}
	}
</style>